home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / doc / example1.c < prev    next >
C/C++ Source or Header  |  1993-09-01  |  2KB  |  81 lines

  1. /*
  2.  * example1.c: oscillating mesh
  3.  *
  4.  * This example module is distributed with the geomview manual.
  5.  * If you are not reading this in the manual, see the "External
  6.  * Modules" chapter of the manual for more details.
  7.  *
  8.  * This module creates an oscillating mesh.
  9.  */
  10.  
  11. #include <math.h>
  12. #include <stdio.h>
  13.  
  14. /* F is the function that we plot
  15.  */
  16. float F(x,y,t)
  17.      float x,y,t;
  18. {
  19.   float r = sqrt(x*x+y*y);
  20.   return(sin(r + t)*sqrt(r));
  21. }
  22.  
  23. main(argc, argv)        
  24.      char **argv;
  25. {
  26.   int xdim, ydim;
  27.   float xmin, xmax, ymin, ymax, dx, dy, t, dt;
  28.  
  29.   xmin = ymin = -5;             /* Set x and y            */
  30.   xmax = ymax = 5;              /*    plot ranges         */
  31.   xdim = ydim = 24;             /* Set x and y resolution */
  32.   dt = 0.1;                     /* Time increment is 0.1  */
  33.  
  34.   /* Geomview setup.  We begin by sending the command
  35.    *            (geometry example { : foo})
  36.    * to geomview.  This tells geomview to create a geom called
  37.    * "example" which is an instance of the handle "foo".
  38.    */
  39.   printf("(geometry example { : foo })\n");
  40.   fflush(stdout);
  41.  
  42.   /* Loop until killed.
  43.    */
  44.   for (t=0; ; t+=dt) {
  45.     UpdateMesh(xmin, xmax, ymin, ymax, xdim, ydim, t);
  46.   }
  47. }
  48.  
  49. /* UpdateMesh sends one mesh iteration to geomview.  This consists of
  50.  * a command of the form
  51.  *    (read geometry { define foo
  52.  *       MESH
  53.  *       ...
  54.  *    })
  55.  * where ... is the actual data of the mesh.  This command tells
  56.  * geomview to make the value of the handle "foo" be the specified
  57.  * mesh.
  58.  */
  59. UpdateMesh(xmin, xmax, ymin, ymax, xdim, ydim, t)
  60.      float xmin, xmax, ymin, ymax, t;
  61.      int xdim, ydim;
  62. {
  63.   int i,j;
  64.   float x,y, dx,dy;
  65.  
  66.   dx = (xmax-xmin)/(xdim-1);
  67.   dy = (ymax-ymin)/(ydim-1);
  68.  
  69.   printf("(read geometry { define foo \n");
  70.   printf("MESH\n");
  71.   printf("%1d %1d\n", xdim, ydim);
  72.   for (j=0, y = ymin; j<ydim; ++j, y += dy) {
  73.     for (i=0, x = xmin; i<xdim; ++i, x += dx) {
  74.       printf("%f %f %f\t", x, y, F(x,y,t));
  75.     }
  76.     printf("\n");
  77.   }
  78.   printf("})\n");
  79.   fflush(stdout);
  80. }
  81.